﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using DataInfo;
using KenLib.BusinessManager;

public partial class APP_frmA_CompBranchHistoryInput : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = @"実習実施場所履歴情報登録";
        ((APP_MasterPage_appCom)this.Master).changeTitle("実習実施場所履歴情報登録");
        ((APP_MasterPage_appCom)this.Master).HideLiArea("frmA_CompBranchHistoryInput");
        if (!IsPostBack)
        {
            this.getYear();
            txt_安全衛生措置.Text = "安全衛生教育の実施等";
            
        }
        if (Session["役"] == null || Session["役"] == "")
        {
            Response.Redirect("~/frmD_Login.aspx");
        }
        else
        {
            CheckSession();
            txt_情報有効開始日.Focus();
            ScriptManager.RegisterStartupScript(UpdatePanel2, UpdatePanel2.GetType(), "regis", "Disable();CheckReady();", true);
            
            validatetxt_情報有効開始日.ErrorMessage = GetError("ER00007");
            //validatetxt_勤務開始時間.ErrorMessage = "勤務開始時間"+GetError("ER00001");
            CustomValidator20.ErrorMessage = GetError("ER00001");
            //validatetxt_勤務終了時間.ErrorMessage = "勤務終了時間" + GetError("ER00001");
            CustomValidator7.ErrorMessage = GetError("ER00001");
            //validateddl_昼休み開始時間.ErrorMessage = "昼休み開始時間" + GetError("ER00001");
            CustomValidator9.ErrorMessage = GetError("ER00001");
            CustomValidator10.ErrorMessage = GetError("ER00018");
            //validateddl_昼休み終了時間.ErrorMessage = "昼休み終了時間" + GetError("ER00001");
            CustomValidator11.ErrorMessage = GetError("ER00001");
            CustomValidator12.ErrorMessage = GetError("ER00018");
            validatetxt_休憩時間.ErrorMessage = GetError("ER00001");
            //validatetxt_所定労働時間.ErrorMessage = GetError("ER00001");
            validatetxt_平均週間労働日数.ErrorMessage = GetError("ER00001");
            validatetxt_年間労働日数.ErrorMessage = GetError("ER00001");
            validatetxt_年間労働日数翌年.ErrorMessage = GetError("ER00001");
            validatetxt_年間労働日数翌々年.ErrorMessage = GetError("ER00001");
            validatetxt_健康診断回数.ErrorMessage = GetError("ER00001");
            validatetxt_前回健康診断実施日.ErrorMessage = GetError("ER00001");
            validateddl_休業４日以上事故有無.ErrorMessage = GetError("ER00001");
            validateddl_死亡事故有無.ErrorMessage = GetError("ER00001");
            validateDropDownList1.ErrorMessage = GetError("ER00001");
            validatetxt労基法違反日.ErrorMessage = GetError("ER00001");
            validatetxt_労基法違反内容.ErrorMessage = GetError("ER00001");
            validatetxt_安全衛生措置.ErrorMessage = GetError("ER00001");
            //regular1.ErrorMessage = "情報有効開始日" + GetError("ER00002");
            //CustomValidator4.ErrorMessage =  GetError("ER00002");
            //regular2.ErrorMessage = "労基法違反日" + GetError("ER00002");
            CustomValidator6.ErrorMessage = GetError("ER00002");
            //regular3.ErrorMessage = "前回健康診断実施日" + GetError("ER00002");
            CustomValidator3.ErrorMessage = GetError("ER00006");
            CustomValidator1.ErrorMessage = GetError("ER00005");
            CustomValidator2.ErrorMessage = GetError("ER00005");
            //regular4.ErrorMessage = "勤務開始時間" + GetError("ER00002");
            CustomValidator5.ErrorMessage = GetError("ER00018");
            //regular5.ErrorMessage = "勤務終了時間" + GetError("ER00002");
            CustomValidator8.ErrorMessage = GetError("ER00018");
            //CustomValidator21.ErrorMessage = GetError("ER00002");
            CustomValidator22.ErrorMessage = GetError("ER00002");
            CustomValidator23.ErrorMessage = GetError("ER00002");
            CustomValidator24.ErrorMessage = GetError("ER00002");
            CustomValidator25.ErrorMessage = GetError("ER00002");
            CustomValidator26.ErrorMessage = GetError("ER00005");
            CustomValidator27.ErrorMessage = GetError("ER00005");
            CustomValidator30.ErrorMessage = GetError("ER00005");
            CustomValidator21.ErrorMessage = GetError("ER00006");
        }
    }


    public void getYear()// kiem tra nam.
    {
        string a = DateTime.Now.Year.ToString();
        for (int i = Int32.Parse(a) - 9; i <= Int32.Parse(a); i++)
        {
            ListItem item = new ListItem(i.ToString(), i.ToString());
            txt_情報有効開始日.Items.Add(item);
        }

    }


    protected void btn_確認_Click(object sender, EventArgs e)
    {

        List<List<String>> list = new List<List<String>>();
        String[] varList = Request.Form.AllKeys;
        for (int i = 3; i < varList.Length; i++)
        {
            string controlName = varList[i];
            string value = Request.Params.Get(controlName).Replace("<", "&lt;");
            value = value.Replace(">", "&gt;");
            string serverControlName = controlName.Replace("ctl00$ContentPlaceHolder1$", "");
            List<String> val = new List<String>();
            val.Add(serverControlName);
            val.Add(value);
            list.Add(val);
        }

        Session["listValuefrmA_CompBranchHistoryInput"] = list;
        
        Response.Redirect("frmA_CompBranchHistoryCheck.aspx");
    }

    public String GetError(string errorid)
    {
        Error er = new Error();
        er.ErrorID = errorid;
        ErrorManager frm_error = new ErrorManager();
        DataTable dt = frm_error.getError(er);
        return dt.Rows[0][2].ToString();
    }


    public void CheckSession()// Session dung de show thong tin khi nguoi dung click button btn_戻る_Click o trang CompBrachHistoryCheck de quay ve trang CompBranchHistoryInput.aspx.
    {
        if (Session["listValuefrmA_CompBranchHistoryInput"] != null)
        {
            List<List<String>> list = new List<List<String>>();
            list = (System.Collections.Generic.List<List<String>>)Session["listValuefrmA_CompBranchHistoryInput"];
            foreach (List<String> str in list)
            {
                if (str[0] == "txt_情報有効開始日")
                {
                    txt_情報有効開始日.Text = str[1];
                }

                if (str[0] == "txt_勤務開始時間")
                {
                    txt_勤務開始時間.Text = str[1];
                }

                if (str[0] == "txt_勤務終了時間")
                {
                    txt_勤務終了時間.Text = str[1];
                }

                if (str[0] == "ddl_昼休み開始時間")
                {
                    ddl_昼休み開始時間.Text = str[1];
                }

                if (str[0] == "ddl_昼休み終了時間")
                {
                    ddl_昼休み終了時間.Text = str[1];
                }

                if (str[0] == "txt_休憩時間")
                {
                    txt_休憩時間.Text = str[1];
                }

                if (str[0] == "txt_所定労働時間")
                {
                    txt_所定労働時間.Text = str[1];
                }
                if (str[0] == "txt_所定労働時間_分")
                {
                    txt_所定労働時間_分.Text = str[1];
                }

                if (str[0] == "txt_平均週間労働日数")
                {
                    txt_平均週間労働日数.Text = str[1];
                }

                if (str[0] == "txt_年間労働日数")
                {
                    txt_年間労働日数.Text = str[1];
                }

                if (str[0] == "txt_年間労働日数翌年")
                {
                    txt_年間労働日数翌年.Text = str[1];
                }

                if (str[0] == "txt_年間労働日数翌々年")
                {
                    txt_年間労働日数翌々年.Text = str[1];
                }

                if (str[0] == "txt_健康診断回数")
                {
                    txt_健康診断回数.Text = str[1];
                }

                if (str[0] == "txt_前回健康診断実施日")
                {
                    txt_前回健康診断実施日.Text = str[1];
                }

                if (str[0] == "ddl_休業４日以上事故有無")
                {

                    ddl_休業４日以上事故有無.Text = str[1];
                }

                if (str[0] == "txt_件数1")
                {
                    txt_件数1.Text = str[1];
                }

                if (str[0] == "txt_人数1")
                {
                    txt_人数1.Text = str[1];

                }

                if (str[0] == "ddl_死亡事故有無")
                {
                    ddl_死亡事故有無.Text = str[1];

                }


                if (str[0] == "txt_件数2")
                {
                    txt_件数2.Text = str[1];

                }

                if (str[0] == "txt_人数2")
                {
                    txt_人数2.Text = str[1];

                }

                if (str[0] == "DropDownList1")
                {


                    DropDownList1.Text = str[1];
                }

                if (str[0] == "txt労基法違反日")
                {
                    txt労基法違反日.Text = str[1];
                    if (str[1] == "2099/12/31")
                    {
                        h1.Value = "";

                    }
                    else
                    {
                        h1.Value = str[1];
                    }

                }

                if (str[0] == "txt_労基法違反内容")
                {
                    txt_労基法違反内容.Text = str[1];
                    if (str[1] == "0000000000000000000000000sdfsdfsfbrtta")
                    {
                        h2.Value = "";
                    }
                    else
                    {
                        h2.Value = str[1];
                    }

                }

                if (str[0] == "txt_安全衛生措置")
                {
                    txt_安全衛生措置.Text = str[1];
                }
            }
        }
        else
        {
            if (Session["Update_frmA_CompHistoryInput"] != null)
            {
                拠点履歴Manager frm = new 拠点履歴Manager();
                DataTable dt = new DataTable();
                int 年度 = Int32.Parse(txt_情報有効開始日.SelectedValue.ToString());
                int 拠点ID = Int32.Parse(Session["拠点ID"].ToString());
                dt = frm.GetYear拠点履歴_TUNG(年度, 拠点ID);
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        //txt_情報有効開始日.SelectedValue = row["年度"].ToString();
                        txt_勤務開始時間.Text = row["勤務開始時間"].ToString();
                        txt_勤務終了時間.Text = row["勤務終了時間"].ToString();
                        ddl_昼休み開始時間.Text = row["昼休み開始時間"].ToString();
                        ddl_昼休み終了時間.Text = row["昼休み終了時間"].ToString();
                        txt_休憩時間.Text = row["休憩合計時間"].ToString();
                        if (Int32.Parse(row["所定労働時間"].ToString()) < 10)
                        {
                            txt_所定労働時間.Text = "0" + row["所定労働時間"].ToString();
                        }
                        else
                        {
                            txt_所定労働時間.Text = row["所定労働時間"].ToString();
                        }
                        if (Int32.Parse(row["所定労働時間_分"].ToString()) < 10)
                        {
                            txt_所定労働時間_分.Text = "0" + row["所定労働時間_分"].ToString();
                        }
                        else
                        {
                            txt_所定労働時間_分.Text = row["所定労働時間_分"].ToString();
                        }
                        txt_平均週間労働日数.Text = row["平均週間労働日数"].ToString();
                        txt_年間労働日数.Text = row["年間労働日数"].ToString();
                        txt_年間労働日数翌年.Text = row["年間労働日数翌年"].ToString();
                        txt_年間労働日数翌々年.Text = row["年間労働日数翌々年"].ToString();
                        txt_健康診断回数.Text = row["検診回数"].ToString();
                        txt_前回健康診断実施日.Text = ConvertDate(row["検診実施日"].ToString());
                        if (row["休業４日事故"].ToString() == "True")
                        {
                            ddl_休業４日以上事故有無.SelectedValue = "1";
                        }
                        else
                        {
                            ddl_休業４日以上事故有無.SelectedValue = "0";
                        }

                        txt_件数1.Text = row["休業４日事故件数"].ToString();
                        txt_人数1.Text = row["休業４日事故人数"].ToString();
                        if (row["死亡事故有無"].ToString() == "True")
                        {
                            ddl_死亡事故有無.SelectedValue = "1";
                        }
                        else
                        {
                            ddl_死亡事故有無.SelectedValue = "0";
                        }
                        txt_件数2.Text = row["死亡事故件数"].ToString();
                        txt_人数2.Text = row["死亡事故人数"].ToString();

                        if (row["労基法違反有無"].ToString() == "True")
                        {
                            DropDownList1.SelectedValue = "1";
                        }
                        else
                        {
                            DropDownList1.SelectedValue = "0";
                        }
                        h1.Value = ConvertDate(row["労基法違反有無日付"].ToString());
                        h2.Value = row["労基法違反有無内容"].ToString();
                        txt_安全衛生措置.Text = row["安全衛生措置"].ToString();


                    }


                }
            }
            else
            {
                
                txt_勤務開始時間.Text = "";
                txt_勤務終了時間.Text = "";
                ddl_昼休み開始時間.Text = "";
                ddl_昼休み終了時間.Text = "";
                txt_休憩時間.Text = "";
                txt_所定労働時間.Text = "";
                txt_所定労働時間_分.Text = "";
                txt_平均週間労働日数.Text = "";
                txt_年間労働日数.Text = "";
                txt_年間労働日数翌年.Text = "";
                txt_年間労働日数翌々年.Text = "";
                txt_健康診断回数.Text = "";
                txt_前回健康診断実施日.Text = "";
                ddl_休業４日以上事故有無.SelectedValue = "-1";
                txt_件数1.Text = "";
                txt_人数1.Text = "";
                ddl_死亡事故有無.SelectedValue = "-1";
                txt_件数2.Text = "";
                txt_人数2.Text = "";
                DropDownList1.SelectedValue = "-1";
                h1.Value = "";
                h2.Value = "";
                txt_安全衛生措置.Text = "安全衛生教育の実施等";
            }
        }

    }
    protected void btn_リセット_Click(object sender, EventArgs e)
    {
        //Session.Remove("listValuefrmA_CompBranchHistoryInput");
        //Response.Redirect("frmA_CompBranchHistoryInput.aspx");
        CheckSession();
    }
    protected void txt_情報有効開始日_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            拠点履歴Manager frm = new 拠点履歴Manager();
            DataTable dt = new DataTable();
            int 年度 = Int32.Parse(txt_情報有効開始日.SelectedValue.ToString());
            int 拠点ID = Int32.Parse(Session["拠点ID"].ToString());
            dt = frm.GetYear拠点履歴_TUNG(年度, 拠点ID);
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    //txt_情報有効開始日.SelectedValue = row["年度"].ToString();
                    txt_勤務開始時間.Text = row["勤務開始時間"].ToString();
                    txt_勤務終了時間.Text = row["勤務終了時間"].ToString();
                    ddl_昼休み開始時間.Text = row["昼休み開始時間"].ToString();
                    ddl_昼休み終了時間.Text = row["昼休み終了時間"].ToString();
                    txt_休憩時間.Text = row["休憩合計時間"].ToString();
                    if (Int32.Parse(row["所定労働時間"].ToString()) < 10)
                    {
                        txt_所定労働時間.Text = "0" + row["所定労働時間"].ToString();
                    }
                    else
                    {
                        txt_所定労働時間.Text = row["所定労働時間"].ToString();
                    }
                    if (Int32.Parse(row["所定労働時間_分"].ToString()) < 10)
                    {
                        txt_所定労働時間_分.Text = "0" + row["所定労働時間_分"].ToString();
                    }
                    else
                    {
                        txt_所定労働時間_分.Text = row["所定労働時間_分"].ToString();
                    }
                    txt_平均週間労働日数.Text = row["平均週間労働日数"].ToString();
                    txt_年間労働日数.Text = row["年間労働日数"].ToString();
                    txt_年間労働日数翌年.Text = row["年間労働日数翌年"].ToString();
                    txt_年間労働日数翌々年.Text = row["年間労働日数翌々年"].ToString();
                    txt_健康診断回数.Text = row["検診回数"].ToString();
                    txt_前回健康診断実施日.Text = ConvertDate(row["検診実施日"].ToString());
                    if (row["休業４日事故"].ToString() == "True")
                    {
                        ddl_休業４日以上事故有無.SelectedValue = "1";
                    }
                    else
                    {
                        ddl_休業４日以上事故有無.SelectedValue = "0";
                    }

                    txt_件数1.Text = row["休業４日事故件数"].ToString();
                    txt_人数1.Text = row["休業４日事故人数"].ToString();
                    if (row["死亡事故有無"].ToString() == "True")
                    {
                        ddl_死亡事故有無.SelectedValue = "1";
                    }
                    else
                    {
                        ddl_死亡事故有無.SelectedValue = "0";
                    }
                    txt_件数2.Text = row["死亡事故件数"].ToString();
                    txt_人数2.Text = row["死亡事故人数"].ToString();

                    if (row["労基法違反有無"].ToString() == "True")
                    {
                        DropDownList1.SelectedValue = "1";
                    }
                    else
                    {
                        DropDownList1.SelectedValue = "0";
                    }
                    h1.Value = ConvertDate(row["労基法違反有無日付"].ToString());
                    h2.Value = row["労基法違反有無内容"].ToString();
                    txt_安全衛生措置.Text = row["安全衛生措置"].ToString();


                }
                Session["Update_frmA_CompHistoryInput"] = "Update";
            }
            else
            {
                //txt_情報有効開始日.SelectedValue = "";
                txt_勤務開始時間.Text = "";
                txt_勤務終了時間.Text = "";
                ddl_昼休み開始時間.Text = "";
                ddl_昼休み終了時間.Text = "";
                txt_休憩時間.Text = "";
                txt_所定労働時間.Text = "";
                txt_所定労働時間_分.Text = "";
                txt_平均週間労働日数.Text = "";
                txt_年間労働日数.Text = "";
                txt_年間労働日数翌年.Text = "";
                txt_年間労働日数翌々年.Text = "";
                txt_健康診断回数.Text = "";
                txt_前回健康診断実施日.Text = "";
                ddl_休業４日以上事故有無.SelectedValue = "-1";
                txt_件数1.Text = "";
                txt_人数1.Text = "";
                ddl_死亡事故有無.SelectedValue = "-1";
                txt_件数2.Text = "";
                txt_人数2.Text = "";
                DropDownList1.SelectedValue = "-1";
                h1.Value = "";
                h2.Value = "";
                txt_安全衛生措置.Text = "安全衛生教育の実施等";
                Session.Remove("Update_frmA_CompHistoryInput");
            }
        }
        catch { }
    }

    public string ConvertDate(string str)// ham convert ngay thang nam.
    {
        if (str == "")
        {
            return str = "";
        }
        else
        {
            string date = str;
            DateTime d1 = DateTime.Parse(date);
            d1.Year.ToString();
            return date = d1.ToString("yyyy/MM/dd");
            
        }
    }

}
